package org.cs.controlmachine;

import org.cs.program.Instruction;

/**
 * 控制单元 CU
 *
 * @author fbin
 * @since 2022/4/5 11:22
 */
public class ControlUnit {
    private static final int OPERATE_CODE_BITS = 0b1111110000000000;
    private static final int DATA_BITS = 0b0000001111111111;
    /**
     * 数据位长度
     */
    private static final int DATA_BIT_LENGTH = 10;
    /**
     * 解析指令
     *
     * @param instruction 指令
     */
    public Instruction analysis(Object instruction) {
        int operateCode = (((int) instruction) & OPERATE_CODE_BITS) >>> DATA_BIT_LENGTH;
        int address = ((int) instruction) & DATA_BITS;
        return new Instruction(operateCode, address);
    }
}
